<template>
  <div>
  	<home-header></home-header>
  	<home-swiper :swiperList="swiperList"></home-swiper>
  	<home-icons :iconList="iconList"></home-icons>
  	<home-recommend :recommendList="recommendList"></home-recommend>
  	<home-weekend :weekendList="weekendList"></home-weekend>
  </div>
</template>

<script>
import homeHeader from './components/header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  name: 'Home',
  components: {
  	homeHeader,
  	HomeSwiper,
  	HomeIcons,
  	HomeRecommend,
  	HomeWeekend
  },
  data (){
  	return {
      lastCity: '',
  		weekendList: [],
  		recommendList: [],
  		iconList: [],
  		swiperList: []
  	}
  },
  computed: {
      ...mapState(['city'])
  },
  methods: {
  	getHomeInfo (){
  		axios.get('/api/index.json' ).then(this.getHomeInfoSucc);
  		axios.get('/api/city.json?city=' + this.city).then(this.getCity);
  	},
  	getHomeInfoSucc (res){
  		var data =  res.data.data;
  		this.swiperList = data.swiperList;
  		this.recommendList = data.recommendList;
  		this.iconList = data.iconList;
  		this.weekendList = data.weekendList;
  	},
  	getCity (res){
  		var city = res.data.data.cities;
  	}
  },
  mounted () {
     this.lastCity = this.city;
    this.getHomeInfo();
  },
  activated (){
    if( this.lastCity !==  this.city) {
      this.lastCity = this.city;
      this.getHomeInfo();
    }
  }
}
</script>

<style>

</style>
